package com.gm;

import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by Administrator on 13-12-22.
 */
public class TextComponentFrame extends GCommonFrame {

    public TextComponentFrame() {
        super();
        setTitle("Text Component Test");

        JMenuBar mainMenu=new JMenuBar();

        JMenu fileMenu=new JMenu("File");
        JMenuItem exitItem=new JMenuItem("Exit");
        fileMenu.add(exitItem);

        exitItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });

        mainMenu.add(fileMenu);
        setJMenuBar(mainMenu);


        JPanel inputPanel=new JPanel();
        inputPanel.setLayout(new GridLayout(2,2));

        final JTextField usernameText=new JTextField();
        final JPasswordField passwordText=new JPasswordField();

        inputPanel.add(new JLabel("User name:",SwingConstants.RIGHT));
        inputPanel.add(usernameText);
        inputPanel.add(new JLabel("Password:",SwingConstants.RIGHT));
        inputPanel.add(passwordText);

        Border inputBorder=BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Information");
        inputPanel.setBorder(inputBorder);
        add(inputPanel, BorderLayout.NORTH);

        final JTextArea multi_Text=new JTextArea(8,8);
        JScrollPane textPanel=new JScrollPane(multi_Text);
        add(textPanel,BorderLayout.CENTER);

        JPanel btnPanel=new JPanel();
        JButton insertBtn=new JButton("Insert");
        btnPanel.add(insertBtn);
        insertBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                multi_Text.append("User Name:"+usernameText.getText()+" Password:"+new String(passwordText.getPassword())+"\n");
            }
        });

        add(btnPanel,BorderLayout.SOUTH);
    }
}
